<template>
  <div class="image-list">
    <div class="image-item" v-for="(item, index) in images" :key="index" @click="handleClick(index)">
      <div class="image-preview">
        <img :src="item.url" :alt="item.name">
      </div>
      <div class="image-info">
        <div class="image-name">{{ item.name }}</div>
        <div class="image-type">{{ item.type }}</div>
      </div>
      <div class="image-checkbox">
        <input type="checkbox" v-model="selected[index]">
      </div>
    </div>
  </div>
</template>

<script>
  export default {
    props: {
      images: {
        type: Array,
        required: true
      }
    },
    data() {
      return {
        selected: []
      }
    },
    methods: {
      handleClick(index) {
        // 点击图片时触发
        this.$emit('click', index)
      }
    }
  }
</script>

<style scoped>
  .image-list {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
  }

  .image-item {
    width: 30%;
    margin-bottom: 20px;
    border: 1px solid #ccc;
    border-radius: 5px;
    overflow: hidden;
    cursor: pointer;
  }

  .image-preview {
    height: 200px;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .image-preview img {
    max-width: 100%;
    max-height: 100%;
  }

  .image-info {
    padding: 10px;
    background-color: #f5f5f5;
    font-size: 14px;
  }

  .image-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .image-checkbox {
    position: absolute;
    top: 10px;
    right: 10px;
  }
</style>
